;--------------------------------------
;
; vdWrite.asm
;
; vdWrite(row,col,len,string,attr)
;
; Byte row      row of string write
; Byte col      column of string write 
; Word len      number of bytes to write
; char *string  pointer to string to write
; Byte attr     attribute of screen write
;
;--------------------------------------
;
; include defs, prototypes and macros
;

include tab6.inc

;--------------------------------------
;
; begin code segment
;

    .Code

vdWrite PROC Pascal PUBLIC USES es ds di ds si bx,row:Byte,
                                                  col:Byte,
                                                  lgth:Word,
                                                  str1:PByte,
                                                  attr:Byte

; ds:si points to source string

IF mdl eq 3
    lds     si,str1
ELSE
    mov     si,str1
ENDIF

; es gets screen segment

 IF mdl eq 3
    push   ds
    mov    ax,SEG scrn_seg
    mov    ds,ax
    mov    ax,ds:scrn_seg
    mov    es,ax
    pop    ds
 ELSE
    mov    ax,scrn_seg
    mov    es,ax
 ENDIF
    sub    ax,ax         ; 0 -> ax
    mov    al,row        ; row -> al
    mov    bl,160        ; 160 = (80 chars wide * 2)
    mul    bl            ; row * scrn width  -> ax
    mov    cl,col        ; column to cl
    sub    ch,ch         ; 0 -> ch
    shl    cx,1          ; col * 2
    add    ax,cx         ; column + (row * scrn width)
    mov    di,ax         ; point di to scrn
    cld                   ; direction increment
    mov    ah,attr       ; make word token
    mov    cx,lgth       ; string length -> cx
    .IF (cx>0)
    jmp vdr1
    .ENDIF
    .WHILE 1
    lodsb   
    .IF (al==0)
    ret
    .ENDIF
    stosw
    .ENDW
vdr1:
    .REPEAT
    lodsb                  ; get byte from string
    stosw                  ; token to screen
    dec    cx
    .UNTIL (cx==0)
    ret
vdWrite    ENDP

    END
    
;
;--------------------------------------    

